import { Loading } from "element-plus";

let loadingCount = 0;
let loading;
let key = true;

const startLoading = () => {
  loading = Loading.service({
    lock: true,
    text: "",
    background: "rgba(0, 0, 0, 0.4)"
  });
  if (key) {
    setTimeout(function() {
      endLoading();
    }, 30000);
  }
};

const endLoading = () => {
  loading.close();
};

export const showLoading = () => {
  if (loadingCount === 0) {
    startLoading();
  }
  loadingCount++;
};

export const hideLoading = () => {
  if (loadingCount <= 0) {
    return;
  }
  loadingCount--;
  if (loadingCount === 0) {
    key = false;
    endLoading();
  }
};
